Make FormatMetadata accept RequestContext, instead of hard coding $wgLang.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegTest.php
1 <?php
2 class JpegTest extends MediaWikiTestCase {
3
4 protected function setUp() {
5 parent::setUp();
6 if ( !extension_loaded( 'exif' ) ) {
7 $this->markTestSkipped( "This test needs the exif extension." );
8 }
9
10 $this->filePath = __DIR__ . '/../../data/media/';
11
12
13 $this->setMwGlobals( 'wgShowEXIF', true );
14
15 $this->backend = new FSFileBackend( array(
16 'name' => 'localtesting',
17 'lockManager' => 'nullLockManager',
18 'containerPaths' => array( 'data' => $this->filePath )
19 ) );
20 $this->repo = new FSRepo( array(
21 'name' => 'temp',
22 'url' => 'http://localhost/thumbtest',
23 'backend' => $this->backend
24 ) );
25
26 $this->handler = new JpegHandler;
27 }
28
29 public function testInvalidFile() {
30 $file = $this->dataFile( 'README', 'image/jpeg' );
31 $res = $this->handler->getMetadata( $file, $this->filePath . 'README' );
32 $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
33 }
34
35 public function testJpegMetadataExtraction() {
36 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
37 $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' );
38 $expected = 'a:7:{s:16:"ImageDescription";s:9:"Test file";s:11:"XResolution";s:4:"72/1";s:11:"YResolution";s:4:"72/1";s:14:"ResolutionUnit";i:2;s:16:"YCbCrPositioning";i:1;s:15:"JPEGFileComment";a:1:{i:0;s:17:"Created with GIMP";}s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
39
40 // Unserialize in case serialization format ever changes.
41 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
42 }
43
44 /**
45 * @covers JpegHandler::getCommonMetaArray
46 */
47 public function testGetIndependentMetaArray() {
48 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
49 $res = $this->handler->getCommonMetaArray( $file );
50 $expected = array(
51 'ImageDescription' => 'Test file',
52 'XResolution' => '72/1',
53 'YResolution' => '72/1',
54 'ResolutionUnit' => 2,
55 'YCbCrPositioning' => 1,
56 'JPEGFileComment' => array(
57 'Created with GIMP',
58 ),
59 );
60
61 $this->assertEquals( $res, $expected );
62 }
63
64 private function dataFile( $name, $type ) {
65 return new UnregisteredLocalFile( false, $this->repo,
66 "mwstore://localtesting/data/$name", $type );
67 }
68 }